package kaoshi.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import kaoshi.dao.impl.personDaoImpl;
import kaoshi.entity.person;
import kaoshi.service.impl.personServiceImpl;
import kaoshi.dao.personDao;

@WebServlet("/xinzenServlet")
public class xinzenServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        //设置响应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        int age = Integer.parseInt(request.getParameter("age"));
        String denj = request.getParameter("denj");
        String bume = request.getParameter("bume");
        person s=new person(name,sex,age,denj,bume);
        personDao person = new personDaoImpl();
        int count = person.insert(s);
        if (count>0){
            out.println("<script type=\"text/javascript\">\n" +
                    "        alert(\"新增成功！\");\n" +
                    "        location.href=\"http://localhost:8888/untitled2_war_exploded/chaxvnServlet\";\n" +
                    "    </script>");
        }else{
            out.println("<script type=\"text/javascript\">\n" +
                    "        alert(\"新增失败！\");\n" +
                    "        location.href=\"http://localhost:8888,/untitled2_war_exploded/chaxvnServlet\";\n" +
                    "    </script>");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
